package goodbaby.dklt.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.classic.core.fragment.BaseFragment;

import goodbaby.dklt.GbbApplication;
import goodbaby.dklt.GbbPreferences;
import goodbaby.dklt.R;
import goodbaby.dklt.activity.AttendanceActivity;
import goodbaby.dklt.activity.ClassActivity;
import goodbaby.dklt.activity.CourseActivity;
import goodbaby.dklt.activity.EducNoticeActivity;
import goodbaby.dklt.activity.LeaveHistoryActivity;
import goodbaby.dklt.activity.ReportWorkActivity;
import goodbaby.dklt.activity.KeywordActivity;
import goodbaby.dklt.bean.ClassListInfo;

/**
 * Created by Li.z on 2016/5/7.
 * 管理
 */
public class ManagerFragment extends BaseFragment {

    public static int fromAttendance = 0;
    public static int fromCourse = 2;
    public static int fromLeave = 1;
    public static int fromRecipe = 3;
    private RelativeLayout rlAttendance;
    private RelativeLayout rlCourse;
    private RelativeLayout rlLeave;
    private RelativeLayout rlRecipe;
    private TextView tvTitle;

    private RelativeLayout rlReportWork;
    private RelativeLayout rlEducNotice;
    private RelativeLayout rlSensitiveWord;

    public int getLayoutResId() {
        return R.layout.fragment_manager;
    }

    public void initData() {
        super.initData();
    }

    public void initView(View paramView) {
        super.initView(paramView);
        tvTitle = (TextView) paramView.findViewById(R.id.tv_common_title);
        tvTitle.setText("管理");
        rlAttendance = (RelativeLayout) paramView.findViewById(R.id.rl_attendance);
        rlAttendance.setOnClickListener(this);
        rlLeave = (RelativeLayout) paramView.findViewById(R.id.rl_leave);
        rlLeave.setOnClickListener(this);
        rlCourse = (RelativeLayout) paramView.findViewById(R.id.rl_course);
        rlCourse.setOnClickListener(this);
        rlRecipe = (RelativeLayout) paramView.findViewById(R.id.rl_recipe);
        rlRecipe.setOnClickListener(this);

        rlReportWork = (RelativeLayout) paramView.findViewById(R.id.rl_report_work);
        rlReportWork.setOnClickListener(this);
        rlEducNotice = (RelativeLayout) paramView.findViewById(R.id.rl_educ_notice);
        rlEducNotice.setOnClickListener(this);
        rlSensitiveWord = (RelativeLayout) paramView.findViewById(R.id.rl_sensitive_word);
        rlSensitiveWord.setOnClickListener(this);

        showWordView();
    }

    public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle) {
        return super.onCreateView(paramLayoutInflater, paramViewGroup, paramBundle);
    }

    public void onDestroyView() {
        super.onDestroyView();
    }

    public void viewClick(View paramView) {
        super.viewClick(paramView);
        switch (paramView.getId()) {
            default:
                break;
            case R.id.rl_attendance:
                Intent localIntent4 = new Intent(getActivity(), AttendanceActivity.class);
                startActivity(localIntent4);
                break;
            case R.id.rl_leave:
                Intent localIntent3 = new Intent(getActivity(), LeaveHistoryActivity.class);
                localIntent3.putExtra("fromItem", fromLeave);
                startActivity(localIntent3);
                break;
            case R.id.rl_course:
                if (Integer.parseInt(GbbPreferences.getRole()) == 2) {
                    Intent localIntent2 = new Intent(getActivity(), ClassActivity.class);
                    startActivity(localIntent2);
                } else {
                    Intent localIntent2 = new Intent(getActivity(), CourseActivity.class);
                    localIntent2.putExtra("fromItem", fromCourse);
                    startActivity(localIntent2);
                }
                break;
            case R.id.rl_recipe:
                Intent localIntent1 = new Intent(getActivity(), CourseActivity.class);
                localIntent1.putExtra("fromItem", fromRecipe);
                startActivity(localIntent1);
                break;

            case R.id.rl_report_work:
                Intent localIntent5 = new Intent(getActivity(), ReportWorkActivity.class);
                localIntent5.putExtra("fromItem", fromRecipe);
                startActivity(localIntent5);
                break;

            case R.id.rl_educ_notice:
                Intent localIntent6 = new Intent(getActivity(), EducNoticeActivity.class);
                startActivity(localIntent6);
                break;

            case R.id.rl_sensitive_word:
                Intent localIntent7 = new Intent(getActivity(), KeywordActivity.class);
                startActivity(localIntent7);
                break;
        }

    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        showWordView();
    }

    private void showWordView() {
        //判断是否是园长
        String role = GbbPreferences.getRole();
        if ("2".equals(role)) {
            //园长
            rlSensitiveWord.setVisibility(View.VISIBLE);
        } else {
            //老师
            rlSensitiveWord.setVisibility(View.GONE);
        }
    }
}
